<?php $db = new Mypdo(); ?>
<?php


if (!empty($_SESSION['login'])&&!empty($_SESSION['email'])){
if(empty($_POST)){

    ?>

    <h1>Crée une charge</h1>

    <form method="post" action="#">

        <p>
        <h3>Information</h3>

        <label for="nom_charge">Nom de la charge :</label><input name="nom_charge" type="text" id="nom_charge" required="required" /><br />
        <label for="montant_charge">Montant :</label><input type="number" name="montant_charge" id="montant_charge" required="required" /><br />
        <label for="tva_charge">Taux Tva % :</label><input type="number" name="tva_charge" id="tva_charge" step="any" required="required" /><br />
        <p><input type="reset" value="Annuler" /><input type="submit" value="Valider" /></p>
    </form>

<?php }else{
    try{
    $charge = new Charge($_POST);
    $charge->setIdLoc($_GET['idl']);
    var_dump($charge);

    $chargeManager = new ChargeManager($db);


    $chargeManager->add($charge);

    header('Location: index.php?page=113&id='.$_GET['idl']);
    }catch (ImmolocException $e){
    ?>

    <div class="erreurSaisi"><p>
            <?php
            echo $e->getMessage();
            //header('Location: #');

            ?>
        </p>
    </div>

<?php
}
}
}else{
    header('Location: index.php');
}